﻿using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using SystemMHB.Domian.DTO;
using SystemMHB.Domian;
using SystemMHB.API.DTOs;
using SystemMHB.API.Application.Command.LogisticsCommand;

namespace SystemMHB.API.Controllers
{
    /// <summary>
    /// 物资信息
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class LogisticsController : ControllerBase
    {
        /// <summary>
        /// 日志
        /// </summary>
        ILogger<LogisticsController> logger;
        /// <summary>
        /// 中介者
        /// </summary>
        IMediator mediator;
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="logger">日志</param>
        /// <param name="mediator">中介者</param>
        public LogisticsController(ILogger<LogisticsController> logger, IMediator mediator)
        {
            this.logger = logger;
            this.mediator = mediator;
        }
        /// <summary>
        /// 添加物资信息
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult<int>> LogisticsAdd(LogisticsAddCommand request)
        {
            ApiResult<int> result = new ApiResult<int>();
            try
            {
                result.Code = await mediator.Send(request);
            }
            catch (Exception ex)
            {
                result.Message = ex.Message;
                result.Code = -1;
                throw;
            }
            return result;
        }
        /// <summary>
        /// 反填物资信息
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ApiResult<Logistics>> LogisticsFan([FromQuery] LogisticsFanCommand request)
        {
            ApiResult<Logistics> result = new ApiResult<Logistics>();
            try
            {
                result.Data = await mediator.Send(request);
            }
            catch (Exception ex)
            {
                result.Message = ex.Message;
                result.Code = -1;
                throw;
            }
            return result;
        }
        /// <summary>
        /// 运输中
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult<int>> LogisticsInTransit(LogisticsInTransitCommand request)
        {
            ApiResult<int> result = new ApiResult<int>();
            try
            {
                result.Code = await mediator.Send(request);
            }
            catch (Exception ex)
            {
                result.Message = ex.Message;
                result.Code = -1;
                throw;
            }
            return result;
        }
        /// <summary>
        /// 待签收
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult<int>> LogisticsSignFor(LogisticsSignForCommand request)
        {
            ApiResult<int> result = new ApiResult<int>();
            try
            {
                result.Code = await mediator.Send(request);
            }
            catch (Exception ex)
            {
                result.Message = ex.Message;
                result.Code = -1;
                throw;
            }
            return result;
        }
    }
}
